package cn.jiedanba.cacert.caserver.conroller;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.jiedanba.cacert.ca.service.CertService;
import cn.jiedanba.cacert.ca.vo.GetCertVo;
import cn.jiedanba.cacert.ca.vo.QueryVo;
import cn.jiedanba.cacert.ca.vo.RevokeVo;
import cn.jiedanba.cacert.common.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/cert")
@Api(value = "证书", tags = "证书控制器")
public class CertController {

	@Resource
	private CertService certService;

	/**
	 * 获取证书
	 * 
	 * @param vo
	 * @return
	 */
	@PostMapping(value = "/getCert")
	@ResponseBody
	@ApiOperation(value = "获取证书", notes = "获取证书")
	public ResponseResult getCert(@RequestBody @Valid GetCertVo vo) {
		return certService.getCert(vo);
	}

	/**
	 * 吊销证书
	 * 
	 * @param vo
	 * @return
	 */
	@PostMapping(value = "/revoke")
	@ResponseBody
	@ApiOperation(value = "吊销证书", notes = "吊销证书")
	public ResponseResult revoke(@RequestBody @Valid RevokeVo vo) {
		return certService.revoke(vo);
	}

	/**
	 * 查询证书
	 * 
	 * @param vo
	 * @return
	 */
	@PostMapping(value = "/query")
	@ResponseBody
	@ApiOperation(value = "查询证书", notes = "查询证书")
	public ResponseResult query(@RequestBody @Valid QueryVo vo) {
		return certService.query(vo);
	}

}
